package com.abiao.shop.redis;

/**
 * @Description: Key前缀抽象类，规定前缀与过期时间
 * @Author: AB
 * @Date: 2021-06-24
 * @Version:v1.0
 */
public abstract class BasePrefix implements KeyPrefix{
    private int expireSeconds;  //过期时间
    private String Prefix;  //前缀

    public BasePrefix(int expireSeconds, String prefix) {
        this.expireSeconds = expireSeconds;
        this.Prefix = prefix;
    }

    public BasePrefix(String prefix) { //默认0代表永不过期
        this(0,prefix);
    }

    @Override
    public int expireSeconds() {
        return expireSeconds;
    }

    /**
     * 将 key 前缀封装为 “类名+prefix”
     * @return
     */
    @Override
    public String getPrefix() {
        String className = getClass().getSimpleName();
        return className + ":" + Prefix;
    }
}
